package com.code.day21;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class Demo06Socket {
    public static void main(String[] args) throws Exception {
        //指定端口号
        DatagramSocket datagramSocket = new DatagramSocket(6666);
        //接收数据包
        byte[] bytes = new byte[1024];
        DatagramPacket datagramPacket = new DatagramPacket(bytes, bytes.length);
        datagramSocket.receive(datagramPacket);
        //拆包
        byte[] data = datagramPacket.getData();
        int length = datagramPacket.getLength();
        String s = new String(data,0,length);
        System.out.println(s);
        //关流
        datagramSocket.close();

    }
}
